#ifndef SINA_API_H
#define SINA_API_H

#include "oauth.h"
#include "SuperApi.h"

class CSinaApi :
	public QObject,
	public CSuperApi
{
	Q_OBJECT
public:
	CSinaApi(stSuperApi* pSuperApi);
	~CSinaApi(void);

public:
	virtual void GetPublicTimeLine(int i);
	virtual void RegisterHandler(CSuperApiHandler* pHandler);
	virtual void AuthorizeXAuth(const QString& username, const QString& password);
	virtual void AuthorizePin();
	virtual stSuperApi* GetApiData(){return m_pSuperApi;}
	virtual bool GetUserInfo(stUserInfo* pSuerInfo,QString qsUserId="");
	virtual void PushNewMessage(QString& qsMsg);

protected:
	QByteArray generateAuthorizationHeader(OAuth::HttpMethod method);
	QByteArray generateAccessHeader(OAuth::HttpMethod method,QString& qsCode);

protected:
	void generateAuthoList(QList<QByteArray>& list);
	QByteArray generateSigBase(QList<QByteArray>& list,OAuth::HttpMethod& method,QByteArray url);
	QByteArray generateHeader(QList<QByteArray>& list,QByteArray url,QByteArray& signature);

protected:
	bool ParseUserInfoXml(QString& data,stUserInfo* pUserInfo);

	bool ParseUserEle(QXmlStreamReader& reader,stUserInfo* pUserInfo);

private:
	CSuperApiHandler* m_pHandler;
	stSuperApi* m_pSuperApi;
};

#endif //SINA_API_H
